// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import ComponentBase from "../component/ComponentBase";



const {ccclass, property} = cc._decorator;

@ccclass
export default class MsgLayer extends ComponentBase {

  
    ok:cc.Node = null;
    closeBtn:cc.Node = null;
    closeAll:cc.Node = null;
    tips:cc.Node = null;
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    okCallBackFunc:any = null;
    exitCallBackFunc:any = null;

    start () {
        this.node.x = cc.winSize.width/2;
        this.node.y = cc.winSize.height/2;
    }

    protected onEnable(): void {
        this.node.x = cc.winSize.width/2;
        this.node.y = cc.winSize.height/2;
    }
    init(msg,ok = null,exit = null,okCallBack = null,exitCallBack = null){
        this.tips.getComponent(cc.Label).string = msg;  
       
        if(ok){
            this.ok.getChildByName("label").getComponent(cc.Label).string = ok;
        }
        if(exit){
            this.closeBtn.getChildByName("label").getComponent(cc.Label).string = exit;
        }

        
        this.okCallBackFunc = okCallBack;
        this.exitCallBackFunc = exitCallBack;

        this.ok.active = okCallBack?true:false;
        this.closeBtn.active = exitCallBack?true:false;;
    }

    closeBtnCallBack(){

        if(this.exitCallBackFunc){
            this.exitCallBackFunc();
        }

        this.node.active = false;
    }

    closeAllCallBack(){
        if(this.exitCallBackFunc){
            this.exitCallBackFunc();
        }

        this.node.active = false;
    }

    okCallBack(){
        if(this.okCallBackFunc){
            this.okCallBackFunc();
        }

        this.node.active = false;
    }

    // update (dt) {}
}
